Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | import { NextResponse, type NextRequest } from 'next/server' import { withAuth, type AuthenticatedContext } from '@/lib/auth/withAuth' import { getUserId } from '@/lib/viewer' import { db } from '@/db' import * as schema from '@/db/schema' import { eq, and } from 'drizzle-orm' /** POST /api/postcards/:postcardId/read — mark a postcard as read */ export const POST = withAuth(async (_request: NextRequest, context: AuthenticatedContext) => { try { const userId = await getUserId() const params = await context.params const postcardId = params.postcardId as string await db .update(schema.numberLinePostcards) .set({ isRead: true, updatedAt: new Date() }) .where( and( eq(schema.numberLinePostcards.id, postcardId), eq(schema.numberLinePostcards.userId, userId) ) ) return NextResponse.json({ success: true }) } catch (err) { console.error('[postcards/read] POST failed:', err) return NextResponse.json({ error: 'Failed to mark as read' }, { status: 500 }) } }) |